/*
 * lib2Desa - Another 2D game library in C++
 * Copyright (C) 2009 Erivaldo Xavier de Lima Filho
 *
 * This program is free software and is distributed under GNU General Public License version 3. You can modify and/or redistribute
 * it under the terms of GPL version 3 or posterior version. This program comes with NO WARRANTY, for more details, see LICENSE,
 * or <http://www.gnu.org/licenses>.
 *
 * Contact info:
 *
 *	Erivaldo Xavier de Lima Filho, desadoc@gmail.com
 *
 */

#include "Core/GameObjectGroup.hpp"

#ifndef _NO_NAMESPACE
namespace lib2Desa {
#endif

GameObjectGroup::GameObjectGroup(void)
 : GameElement(null)
{

}

GameObjectGroup::~GameObjectGroup(void)
{
	std::list<shared_ptr<GameObject> >::iterator it = objects.begin();

	for(; it != objects.end(); it++)
	{
		(*it) = null;
	}
}

void GameObjectGroup::draw(const shared_ptr<IGraphicDevice>& gd) const
{
	std::list<shared_ptr<GameObject> >::const_iterator it = objects.begin();

	for(; it != objects.end(); it++)
	{
		(*it)->draw(gd);
	}
}

bool GameObjectGroup::run(u32 ml)
{
	if(!objects.size()) return false;

	std::list<shared_ptr<GameObject> >::iterator it = objects.begin();

	for(; it != objects.end(); it++)
	{
		(*it)->run(ml);
	}

	return true;
}

void GameObjectGroup::add(const shared_ptr<GameObject>& o)
{
	objects.push_back(o);
}

void GameObjectGroup::remove(const shared_ptr<GameObject>& o)
{
	std::list<shared_ptr<GameObject> >::iterator it = objects.begin();

	for(; it != objects.end(); it++)
	{
		if(o == (*it))
		{
			objects.erase(it);
			return;
		}
	}
}

std::list<shared_ptr<GameObject> >& GameObjectGroup::getObjects(void)
{
	return objects;
}

#ifndef _NO_NAMESPACE
}
#endif
